package source.model;

/**
 * This class is used to map objects to an X, Y coordinate so the objects
 * position in game can be deduced.
 * 
 * @author Sean Larson
 *
 */
public class Position {
	public static int xBound;
	public static int yBound;
	
	private int x, y;
	
	private boolean isValidPosition;
	
	public static void setBounds(int x, int y) {
		Position.xBound = x;
		Position.yBound = y;
	}
	
	public int getX() { return this.x; }
	public int getY() { return this.y; }
	
	public boolean setPosition( int newX, int newY ) {
		if (checkBounds( newX, newY )) {
			this.x = newX;
			this.y = newY;
			return true;
		}
		else
			return false;
	}
	
	public Position( int x, int y ) {
		isValidPosition = setPosition(x, y);
	}
	
	public boolean isValid() { return isValidPosition; }
	
	private boolean checkBounds( int x, int y ) {
		if ( x >= 0 && x < Position.xBound && y >= 0 && y < Position.yBound) 
			return true;
		else
			return false;
	}
	
	public boolean isEquals(Position p){
		return this.x == p.getX() && this.y == p.getY();
	}

	public String toString() {
		return "x: " + this.x + " y: " + this.y;
	}
}
